home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 07 - 1991 / 07.04 Apr 91 / Code Optimizing / Sources / Dummy.FPU.a < prev    next >
Encoding:
Text File  |  1990-04-28  |  5.6 KB  |  151 lines  |  [TEXT/MPS ]

  1.       MACHINE MC68020
  2.       MC68881
  3. ;-------------------------------------------------
  4. DUMMY       PROC        EXPORT
  5. ;- - - - - - - - - - - - - - - - - - - - - - - - -
  6. ;  Performs the matrix multiplication C = A * B.
  7. ;
  8. ;  (This is a DUMMY version which does no
  9. ;  floating-point arithmetic; it is used for
  10. ;  measuring the amount of indexing overhead.)
  11. ;
  12. ;  Calling sequence (FORTRAN):
  13. ;      CALL DUMMY (A, B, C, L, M, N)
  14. ;
  15. ;  where
  16. ;      A is an array with L rows and M columns
  17. ;      B is an array with M rows and N columns
  18. ;      C is an array with L rows and N columns
  19. ;      L, M, and N are INTEGERs.
  20. ;
  21. ;  NOTE:  All arrays must be completely filled,
  22. ;  with no gaps. Do not try to pass part of an
  23. ;  array unless it forms a contiguous block of
  24. ;  memory locations.
  25. ;
  26. ;  April 1990
  27. ;  Jon Bell, Dept. of Physics & Computer Science
  28. ;  Presbyterian College, Clinton SC 29325 
  29. ;
  30. ;  Written for MPW Assembler, v3.0.
  31. ;- - - - - - - - - - - - - - - - - - - - - - - - -
  32. ;  Locations of arguments to the subroutine,
  33. ;  relative to the address stored in register A6.
  34. a           EQU     28      ; addr. of a
  35. b           EQU     24      ; addr. of b
  36. c           EQU     20      ; addr. of c
  37. l           EQU     16      ; addr. of # rows in a
  38. m           EQU     12      ; addr. of # cols in a
  39. n           EQU     8       ; addr. of # cols in b
  40. ;  Locations of local variables, relative to the
  41. ;  address stored in register A6.
  42. termCount   EQU  -4  ; initial value of term index
  43. rowCount    EQU  -8  ; initial value of col. index
  44. aColSize    EQU -12  ; # of bytes per column of a
  45. bColSize    EQU -16  ; # of bytes per column of b
  46. ;  Other constants.
  47. ParamSize   EQU  24  ; # of bytes of parameters
  48. LocalSize   EQU -16  ; # of bytes of local var's
  49. zero        EQU $0F  ; 68882 code for constant 0
  50. ;  Register usage.
  51. aPtr        EQU  A2  ; pointer into a
  52. bPtr        EQU  A3  ; pointer into b
  53. cPtr        EQU  A4  ; pointer into c
  54. rowIndex    EQU  D3  ; row-loop index
  55. colIndex    EQU  D4  ; column-loop index
  56. termIndex   EQU  D5  ; term-loop index
  57. aRowBase    EQU  D6  ; start of current row in a
  58. bColBase    EQU  D7  ; start of current col. in b
  59. term        EQU  FP0 ; one term for an elem. of c
  60. sum         EQU  FP1 ; sum for an element of c
  61. ;- - - - - - - - - - - - - - - - - - - - - - - - -
  62. ;  Set up the stack frame, and save registers on
  63. ;  the stack.
  64.       LINK        A6, #LocalSize
  65.       MOVEM.L     A2-A4/D3-D7, -(SP)
  66. ;  Calculate and save the length of 
  67. ;  one column of a.
  68.       MOVE.L      l(A6), A0
  69.       MOVE.L      (A0), D0      ; # of rows
  70.       MULU        #12, D0       ; bytes per column
  71.       MOVE.L      D0, aColSize(A6)
  72. ;  Calculate and save the length of 
  73. ;  one column of b.
  74.       MOVE.L      m(A6), A0
  75.       MOVE.L      (A0), D0      ; # of rows
  76.       MULU        #12, D0       ; bytes per column
  77.       MOVE.L      D0, bColSize(A6)
  78. ;  Save the initial value of the term index.
  79.       MOVE.L      m(A6), A0
  80.       MOVE.L      (A0), termCount(A6)
  81. ;  Save the initial value of the row index.
  82.       MOVE.L      l(A6), A0
  83.       MOVE.L      (A0), rowCount(A6)
  84. ;  Initialize the column index.
  85.       MOVE.L      n(A6), A0
  86.       MOVE.L      (A0), colIndex
  87. ;  Initialize the base address of the current
  88. ;  column in b to the start of b.
  89.       MOVE.L      b(A6), bColBase
  90. ;  Initialize the pointer into c.
  91.       MOVE.L      c(A6), cPtr
  92. BeginColLoop      ;  Cycle over the columns of c.
  93.             SUBQ.L      #1, colIndex
  94.             BMI.S       EndColLoop
  95.       ;  Initialize the row index.
  96.             MOVE.L      rowCount(A6), rowIndex
  97.       ;  Initialize the base address of the
  98.       ;  current row in a to the start of a.
  99.             MOVE.L      a(A6), aRowBase
  100. BeginRowLoop      ; Cycle over the rows of c.
  101.                   SUBQ.L      #1, rowIndex
  102.                   BMI.S       EndRowLoop
  103.             ;  Initialize the a and b pointers 
  104.             ;  for the next sum of terms.
  105.                   MOVE.L      aRowBase, aPtr
  106.                   MOVE.L      bColBase, bPtr
  107.             ;  Initialize the sum.
  108.                   FMOVECR.X   #zero, sum
  109.             ;  Initialize the term index.
  110.                   MOVE.L  termCount(A6), termIndex
  111. BeginTermLoop     ; Cycle over the terms 
  112.                   ; in the sum.
  113.                         SUBQ.L      #1, termIndex
  114.                         BMI.S       EndTermLoop
  115.                   ;  Multiply the current element
  116.                   ;  of b by the current element
  117.                   ;  of a, and advance to the
  118.                   ;  next element in the current
  119.                   ;  column of b.
  120.                   ;     FMOVE.X     (bPtr)+, term
  121.                   ;     FMUL.X      (aPtr), term
  122.                   ;  Add the new term to the sum.
  123.                   ;     FADD.X      term, sum
  124.                   ;  Advance to the next element
  125.                   ;  in the current row of a.
  126.                         ADDA.L  aColSize(A6), aPtr
  127.                         BRA.S       BeginTermLoop
  128. EndTermLoop
  129.             ;  Move the sum into the current
  130.             ;  element of c, and advance to the
  131.             ;  next row in the current 
  132.             ;  column of c.
  133.                   FMOVE.X     sum, (cPtr)+
  134.             ;  Advance to the next row in the
  135.             ;  current column of a.
  136.                   ADD.L       #12, aRowBase
  137.                   BRA.S       BeginRowLoop
  138. EndRowLoop
  139.       ;  Advance to next column in b.
  140.             ADD.L       bColSize(A6), bColBase
  141.             BRA.S       BeginColLoop
  142. EndColLoop
  143. ;  All done.  Restore the saved registers, 
  144. ;  clean up the stack and return.
  145.       MOVEM.L     (SP)+, A2-A4/D3-D7
  146.       UNLK        A6
  147.       RTD         #ParamSize
  148.       DC.B        'DUMMY   ' ; label for debugger
  149.       ENDPROC
  150.       END
  151.